package rps;

import Group.Player;
import rps.RPSEnum;
import rps.Result;

public class RockPaperScissors {

	//get the result for one move
	public Result play(RPSEnum p1, RPSEnum p2){

		if(p1==p2)return Result.TIE;
		else{
			if(p1==RPSEnum.PAPER && p2==RPSEnum.SCISSORS)return Result.LOST;
			else if(p1==RPSEnum.SCISSORS && p2==RPSEnum.ROCK)return Result.LOST;
			else if(p1==RPSEnum.ROCK && p2==RPSEnum.PAPER)return Result.LOST;
		}

		return Result.WIN;
	}

	public Result play(Player p1, Player p2){
		int i;
		Result tmp;
		//play 10 moves
		for(i=0;i<10;i++){
			tmp=play(p1.getNextMove(),p2.getNextMove());

			switch(tmp){
			case TIE:
				p2.IncrementScore();
			case WIN:
				p1.IncrementScore();
				break;
			case LOST:
				p2.IncrementScore();
				break;
			default:
				//error
			}
		}
		
		//find the results
		if(p1.getScore()>p2.getScore())return Result.WIN;
		else if(p1.getScore()<p2.getScore())return Result.LOST;
		return Result.TIE;

	}
}
